<?php

namespace App\Model;


use Illuminate\Support\Facades\DB;

class RoomVote extends BaseModel
{
    protected $table_room_vote_topic = "room_vote_topic"; //房间投票话题表
    const DEFAULT_REPUTATION = 100; //默认分数

    public function __construct(array $attributes = [])
    {
        parent::__construct();
    }

    /**
     * 读取所有话题
     * @return array
     */
    public function getTopics()
    {
        $where['will_be_deleted'] = 0;
        $data = DB::connection($this->connection)
            ->table($this->table_room_vote_topic)
            ->where($where)
            ->get(['id','title']);
        return $this->objToArray($data);
    }

    /**
     * 编辑/新增 话题
     * @return array
     */
    public function editTopic($id, $title)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/roomVoteTopic/edit', [
            'id' => $id,
            'title' => $title
        ]);
    }

    /**
     * 删除 话题
     * @return array
     */
    public function delTopic($id)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/roomVoteTopic/del', ['id' => $id]);
    }

}

